package com.aiyige.page.my.message.notifymessage.ordermessage.adapter;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.message.notifymessage.ordermessage.model.OrderMessage;
import com.aiyige.page.my.message.util.MessageUtil;
import com.aiyige.utils.DateFormatUtil;
import com.aiyige.utils.StringUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/8/14.
 */

public class OrderMessageAdapter extends BaseQuickAdapter<OrderMessage, OrderMessageAdapter.ViewHolder> {


    public OrderMessageAdapter() {
        super(R.layout.order_message_item, new LinkedList<OrderMessage>());
    }

    @Override
    protected void convert(ViewHolder helper, OrderMessage data) {
        helper.bindData(data);
    }

    public static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.otherHeadIv)
        ImageView otherHeadIv;
        @BindView(R.id.otherNameTv)
        TextView otherNameTv;
        @BindView(R.id.otherTimeTv)
        TextView otherTimeTv;
        @BindView(R.id.ordernoTv)
        TextView ordernoTv;
        @BindView(R.id.contactTv)
        TextView contactTv;
        @BindView(R.id.otherOrderMessageTv)
        TextView otherOrderMessageTv;
        @BindView(R.id.coverIv)
        ImageView coverIv;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.mediaTitleTv)
        TextView mediaTitleTv;
        @BindView(R.id.mediaReleaseDateTv)
        TextView mediaReleaseDateTv;
        @BindView(R.id.priceTv)
        TextView priceTv;
        @BindView(R.id.quantityTv)
        TextView quantityTv;
        @BindView(R.id.refundedLayout)
        View refundedLayout;
        @BindView(R.id.rejectRefundLayout)
        View rejectRefundLayout;
        @BindView(R.id.rejectReasonTv)
        TextView rejectReasonTv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            addOnClickListener(R.id.otherHeadIv);
            addOnClickListener(R.id.otherNameTv);
            addOnClickListener(R.id.orderLayout);
        }

        public void bindData(OrderMessage data) {
            otherNameTv.setText(data.getOtherName());
            Glide.with(itemView.getContext())
                    .load(data.getOtherAvatar())
                    .apply(RequestOptions.circleCropTransform())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_head))
                    .into(otherHeadIv);
            Glide.with(itemView.getContext())
                    .load(data.getCover())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_image_bg))
                    .into(coverIv);
            otherTimeTv.setText(DateFormatUtil.formatMS("yyyy-MM-dd HH:mm:ss", data.getOtherTime()));
            mediaTitleTv.setText(data.getMediaTitle());
            ordernoTv.setText(String.valueOf(data.getOrderNo()));
            contactTv.setText(data.getContact());
            otherOrderMessageTv.setText(data.getOtherOrderMessage());
            mediaReleaseDateTv.setText(DateFormatUtil.formatMS("yyyy-MM-dd", data.getMediaReleaseDate()));
            priceTv.setText(StringUtils.getString(R.string.currency_symbols) + StringUtils.priceFormat(data.getPrice()));
            quantityTv.setText("x" + data.getQuantity());
            switch (data.getOrderStatus()) {
                case MessageUtil.ORDER_STATUS_REFUNDED:
                    refundedLayout.setVisibility(View.VISIBLE);
                    rejectRefundLayout.setVisibility(View.GONE);
                    break;
                case MessageUtil.ORDER_STATUS_REJECT_REFUND:
                    refundedLayout.setVisibility(View.GONE);
                    rejectRefundLayout.setVisibility(View.VISIBLE);
                    rejectReasonTv.setText(data.getRejectReason());
                    break;
                default:
                    refundedLayout.setVisibility(View.GONE);
                    rejectRefundLayout.setVisibility(View.GONE);
                    break;
            }
        }
    }
}
